package com.bawei.shoppingcar.gridviewgift_demo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bawei.shoppingcar.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;

import java.util.List;

public class GiftAdapter extends BaseAdapter {
    private List<GiftEntity.DataBean> list;
    private Context context;

    public GiftAdapter(List<GiftEntity.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null){
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_gift, null);
            viewHolder.iv = view.findViewById(R.id.iv);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }
        //图片：load(网址).into(imageView);
        Glide.with(context)
                .load(list.get(i).getGiftpath())
                .transform(new CenterCrop(),new RoundedCorners(20))
                .into(viewHolder.iv);
        return view;
    }
    class ViewHolder{
        ImageView iv;
    }
}
